package com.example.worldcupsever;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.widget.TextView;
import android.os.Handler;

public class SpinActivity extends AppCompatActivity {
    TextView mTvSpin;
    private Message msg;

    Handler handler=new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 101) {
                mTvSpin.setText(msg.arg1 + "s");
            }
        }
};
Thread thread = new Thread(new Runnable() {
        int counter=3;
@Override
public void run() {
        while (counter >0) {
        counter--;
        try {
        Thread.sleep(1000);
        } catch (InterruptedException e) {
        e.printStackTrace();
        }
        Message message = handler.obtainMessage();
        message.what = 101;
        message.arg1 = counter;
        handler.sendMessage(message);//发送消息
        }
        Intent intent = new Intent(SpinActivity.this, MainActivity.class);
        startActivity(intent);
        SpinActivity.this.finish();
        }
        });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spin);
        mTvSpin = findViewById(R.id.tv_spin);
        thread.start();
    }


        }
